package com.hishop.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hishop.common.utils.PageUtils;
import com.hishop.common.utils.Query;
import com.hishop.member.dao.MemberLevelDao;
import com.hishop.member.entity.MemberLevelEntity;
import com.hishop.member.service.MemberLevelService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("memberLevelService")
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelDao, MemberLevelEntity> implements MemberLevelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String key = (String) params.get("key");

        QueryWrapper<MemberLevelEntity> memberLevelEntityQueryWrapper = new QueryWrapper<MemberLevelEntity>();

        if (!StringUtils.isEmpty(key)) {
            memberLevelEntityQueryWrapper.eq("id",key)
                    .or().like("name",key);
        }

        IPage<MemberLevelEntity> page = this.page(
                new Query<MemberLevelEntity>().getPage(params),
                memberLevelEntityQueryWrapper
        );

        return new PageUtils(page);
    }

}